/*************************************************
 *FileName:      guide.js
 *Description:   引导页.js
 *Others:        陈灿
 *************************************************/
    /*
     * 启动
     */
    mui.init();
    mui('.mui-scroll-wrapper').scroll({
        indicators: false,      //是否显示滚动条 默认为true
        deceleration: 0.003,    //阻尼系数,系数越小滑动越灵敏 默认0.0006
        bounce: true           //是否启用回弹 默认true
    });
    
    /*
     * 变量初始化
     */
    var uid = localStorage.replace_uid;
    var token = localStorage.replace_token;
    localStorage.welcome='false';
    /*
     * 主程序
     */ 
    
    $(document).ready(function() 
    {
        //样式加载
        pagecss();
    });
    function pagecss(){
        mui.plusReady(function(){
            if(plus.networkinfo.getCurrentType() == plus.networkinfo.CONNECTION_NONE) {//判断是否开网
                mui.toast("网络未连接,请打开网络");
            }
        });
        $('#guide').on('tap','.img',function(){
            localStorage.guideurl = $(this).attr('data-url');
            var t2='personal';
            var op =new RegExp(t2).test(localStorage.guideurl);
            if(op){
                if(!localStorage.replace_uid){
                    mui.toast('请先登录！')
                    location.href='login.html';
                }else{
                    common.pageTransition('index.html');
                }
            }else{
                plus.runtime.openURL(localStorage.guideurl);
                localStorage.guideurl=null;
            }
        })
        
        $.ajax({
            type: "post",
            url: DOMAIN_NAME +'/index.php/api/Ads/getGuideAds' ,
            dataType:'jsonp',
            data: {},
            success: function(data) {
                var ohtml='';
                var oli ='<span class="swiper-pagination-bullet swiper-pagination-bullet-active">';
                if(data.error_code == 0){
                    for(var i=0 ; i<data.data.length; i++){
                        ohtml+='<div class="swiper-slide"><a class="g-a" ><img class="img" data-url="'+data.data[i].url+'" src="'+DOMAIN_NAME+data.data[i].img+'" /></a></div>';
                        i>0 ?oli +='<span class="swiper-pagination-bullet"></span>':null;
                    }
                    $('#guide .swiper-wrapper').html(ohtml);
                    $('#guide .swiper-pagination').html(oli);
                }else{
                    $('#guide').html('');
                }
                var swiper = new Swiper('.swiper-container', {
                    pagination: '.swiper-pagination',
                    paginationClickable :true,
                });
                
                var client=$(document.body)[0].clientWidth;
                var swiper=new Swiper(".swiper-container",{
                    paginationClickable:true,
                    onTouchEnd:function(swiper){
                        dis=client*($(".swiper-slide").length-1)+10;
                        TR=swiper.translate
                        if(TR<-dis){
                            swiper.setWrapperTranslate(TR);
                            localStorage.guideurl = null;
                            if(!localStorage.replace_uid){
                                location.href='login.html';
                            }else{
                                common.pageTransition('index.html');
                            }
                        }
                    }
                })
            }
        });
    }
